package com.hileto.inf.utils.spring;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Copyright: Copyright (c) 2012
 *     深圳市海乐淘电子商务有限公司
 * @Author : 曾林宝
 * @CreateTime : 2013-1-21 上午10:45:22
 *
 * @Description: spring bean 工厂
 */
public final class SpringFactory implements ApplicationContextAware ,BeanPostProcessor{
	private Log logger = LogFactory.getLog(getClass());
	private static ApplicationContext context;

	public final void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		SpringFactory.context = applicationContext;
	}

	/**
	 * @Description : 根据ID取得Bean.
	 * @Author : 曾林宝
	 * @CreateTime : 2013-1-21 上午10:45:54
	 * @param id
	 * @return
	 */
	public final static Object getObject(String id) {
		Object object = null;
		object = context.getBean(id);
		return object;
	}

	public final Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;
	}

	public final Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		logger.debug("Bean[" + beanName + "] initialization [" + bean + "].");
		return bean;
	}
}
